package com.cn.sys.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


//import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.stereotype.Controller;

import com.cn.utils.FormSubmitResult;
import com.github.pagehelper.PageInfo;
import com.cn.sys.entity.TestEntity;
import com.cn.sys.service.TestService;




/**
 * 测试
 * 
 * @author admin
 * @email yan@gmail.com
 * @date 2017-07-07 16:57:51
 */
@Controller
@RequestMapping("test")
public class TestController {
	@Autowired
	private TestService testService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	//@RequiresPermissions("test:list")
	public FormSubmitResult list(@RequestParam Map<String, Object> params){
		//查询列表数据
		PageInfo<TestEntity> pageinfo=testService.findPage(params);
		
		return FormSubmitResult.SUCCESS().put("page", pageinfo);	
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	//@RequiresPermissions("test:info")
	public FormSubmitResult info(@PathVariable("id") String id){
		Map<String, Object> params=new HashMap<String, Object>();
		params.put("id", id);
		TestEntity test = testService.get(params);
		return FormSubmitResult.SUCCESS().put("test", test);
	}
	
	/**
	 * 保存
	 * @throws Exception 
	 */
	@RequestMapping("/save")
	//@RequiresPermissions("test:save")
	public FormSubmitResult save(@RequestBody TestEntity test) throws Exception{
		testService.save(test);
		
		return FormSubmitResult.SUCCESS();

	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	//@RequiresPermissions("test:update")
	public FormSubmitResult update(@RequestBody TestEntity test){
		testService.update(test);
		
		return FormSubmitResult.SUCCESS();
	}
	
	/**
	 * 删除
	 * @throws Exception 
	 */
	@RequestMapping("/delete")
	//@RequiresPermissions("test:delete")
	public FormSubmitResult delete(@RequestBody String[] ids) throws Exception{
		testService.deleteByIds(ids);
		
		return FormSubmitResult.SUCCESS();
	}
	
	
	@RequestMapping("/oper")
	public String oper(@RequestParam Map<String, Object> params){
		
		return "testOper";
	}
	
}
